package com.learning.springcloudconsumer.service;

import com.learning.springcloudconsumer.bean.User;
import com.learning.springcloudconsumer.client.ProducerUserClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCollapser;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.Future;

import static com.netflix.hystrix.HystrixCollapser.Scope.GLOBAL;

/**
 * (description)
 *
 * @author jinlong.liao on 2018/3/31
 */
@Service
public class UserService {

    @Autowired
    ProducerUserClient producerUserClient;

    @HystrixCollapser(batchMethod = "listAll", scope = GLOBAL, collapserProperties = {
            @HystrixProperty(name = "timerDelayInMilliseconds", value = "50"),
            @HystrixProperty(name = "maxRequestsInBatch", value = "200"),
    })
    public Future<User> futureUser(Integer id) {
        System.out.println("futureUser：" + id);
        return null;
    }

    @HystrixCommand
    public List<User> listAll(List<Integer> ids) {
        return producerUserClient.list(ids);
    }
}
